package com.crm.service.impl.activityManager;

import com.crm.dao.mapper.activityManager.CustomerProductActivityRelationMapper;
import com.crm.model.entity.activityManager.CustomerProductActivityRelation;
import com.crm.model.entity.activityManager.CustomerProductActivityRelationExample;
import com.crm.service.activityManager.CustomerProductActivityRelationDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luojie
 * @date 2021/2/23 11:23
 */
@Service
public class CustomerProductActivityRelationDbServiceImpl implements CustomerProductActivityRelationDbService {

    @Autowired
    private CustomerProductActivityRelationMapper customerProductActivityRelationMapper;

    @Override
    public Boolean insertProductActivityRelation(CustomerProductActivityRelation customerProductActivityRelation) {
        int num = customerProductActivityRelationMapper.insert(customerProductActivityRelation);
        return num > 0;
    }

    @Override
    public List<CustomerProductActivityRelation> selectProductDropDownSelectedListByActivityId(String activityId) {
        CustomerProductActivityRelationExample customerProductActivityRelationExample = new CustomerProductActivityRelationExample();
        CustomerProductActivityRelationExample.Criteria criteria = customerProductActivityRelationExample.createCriteria();
        criteria.andProductActivityIdEqualTo(activityId);
        List<CustomerProductActivityRelation> customerProductActivityRelationList = customerProductActivityRelationMapper.selectByExample(customerProductActivityRelationExample);
        return customerProductActivityRelationList;
    }

    @Override
    public Boolean deleteActivityRelationByActivityId(String activityId) {
        Boolean result = false;
        CustomerProductActivityRelationExample customerProductActivityRelationExample = new CustomerProductActivityRelationExample();
        CustomerProductActivityRelationExample.Criteria criteria = customerProductActivityRelationExample.createCriteria();
        criteria.andProductActivityIdEqualTo(activityId);
        int num = customerProductActivityRelationMapper.deleteByExample(customerProductActivityRelationExample);
        if(num>0){
            result = true;
        }
        return result;
    }
}
